package com.springboot.cloud.demos.producer.rest;

import com.springboot.cloud.common.core.entity.vo.Result;
import com.springboot.cloud.common.web.redis.CacheDuration;
import com.springboot.cloud.common.web.redis.ExpireTimeConstant;
import com.springboot.cloud.demos.entity.form.MomentForm;
import com.springboot.cloud.demos.entity.param.MomentQueryParam;
import com.springboot.cloud.demos.entity.po.Moment;
import com.springboot.cloud.demos.entity.po.User;
import com.springboot.cloud.demos.producer.service.IMomentService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/moment")
@CacheDuration(duration = ExpireTimeConstant.ONE_DAY)
@Api("moment")
@Slf4j
public class MomentController {

    @Autowired
    private IMomentService momentService;

    @ApiOperation(value = "新增产品", notes = "新增一个产品")
    @ApiImplicitParam(name = "momentForm", value = "新增产品form表单", required = true, dataType = "MomentForm")
    @PostMapping
    public Result<Moment> add(@Valid @RequestBody MomentForm momentForm) {
        log.info("name:{}", momentForm);
        Moment moment = momentForm.toPo(Moment.class);
        momentService.add(moment);
        return Result.success(moment);
    }

    @ApiOperation(value = "删除产品", notes = "根据url的id来指定删除对象")
    @ApiImplicitParam(paramType = "path", name = "id", value = "产品ID", required = true, dataType = "long")
    @DeleteMapping(value = "/{id}")
    public Result delete(@PathVariable String id) {
        return Result.success(momentService.delete(id));
    }

    @ApiOperation(value = "修改产品", notes = "修改指定产品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "产品ID", required = true, dataType = "long"),
            @ApiImplicitParam(name = "userMomentForm", value = "产品实体", required = true, dataType = "MomentForm")
    })
    @PutMapping(value = "/{id}")
    public Result update(@PathVariable String id, @Valid @RequestBody MomentForm userMomentForm) {
        Moment userMoment = userMomentForm.toPo(Moment.class);
        userMoment.setId(id);
        return Result.success(momentService.update(userMoment));
    }

    @ApiOperation(value = "获取产品", notes = "获取指定产品信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "产品ID", required = true, dataType = "string")
    @GetMapping(value = "/{id}")
    public Result get(@PathVariable String id) {
        log.info("get with id:{}", id);
        return Result.success(momentService.get(id));
    }

    @ApiOperation(value = "获取产品", notes = "获取指定产品信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "产品ID", required = true, dataType = "string")
    @GetMapping(value = "/getMomentMap")
    public Result getMomentMap(String id) {
        log.info("get with id:{}", id);
        return Result.success(momentService.getMomentMap(id));
    }


    @ApiOperation(value = "动态列表", notes = "查询制定用户动态列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "起始页", required = true, dataType = "int"),
            @ApiImplicitParam(name = "PageSize", value = "页大小", required = true, dataType = "int"),
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "string"),
            @ApiImplicitParam(name = "type", value = "动态类型，0：普通，1广播", required = true, dataType = "int")
    })
    @RequestMapping(value = "/list/{userId}", method = RequestMethod.GET)
    public Result getLatestLevel(@PathVariable(value = "userId") String userId, Integer type, Integer pageNo, Integer pageSize) {
        return Result.success(momentService.list(userId, type, pageNo, pageSize));
    }

    @ApiOperation(value = "关注的动态", notes = "查询关注的动态列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "登录用户ID", required = true, dataType = "string"),
            @ApiImplicitParam(name = "pageNo", value = "起始页", required = true, dataType = "int"),
            @ApiImplicitParam(name = "PageSize", value = "页大小", required = true, dataType = "int"),
            @ApiImplicitParam(name = "sex", value = "1男，2女", required = true, dataType = "int"),
            @ApiImplicitParam(name = "real", value = "真人认证，0：不限，1认证", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pretty", value = "女神认证，0：不限，1认证", required = true, dataType = "int")
    })
    @RequestMapping(value = "/followList", method = RequestMethod.GET)
    public Result followList(String userId, Integer sex, Integer real, Integer pretty, Integer pageNo, Integer pageSize) {
        return Result.success(momentService.followList(userId, sex, real, pretty, pageNo, pageSize));
    }

    @ApiOperation(value = "推荐的动态", notes = "查询推荐的动态列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "起始页", required = true, dataType = "int"),
            @ApiImplicitParam(name = "PageSize", value = "页大小", required = true, dataType = "int"),
            @ApiImplicitParam(name = "sex", value = "1男，2女", required = true, dataType = "int"),
            @ApiImplicitParam(name = "real", value = "真人认证，0：不限，1认证", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pretty", value = "女神认证，0：不限，1认证", required = true, dataType = "int")
    })
    @RequestMapping(value = "/recommendList", method = RequestMethod.GET)
    public Result recommendList(String userId, Integer sex, Integer real, Integer pretty, Integer pageNo, Integer pageSize) {
        return Result.success(momentService.recommendList(userId, sex, real, pretty, pageNo, pageSize));
    }

    @ApiOperation(value = "广播动态", notes = "查询广播动态列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "起始页", required = true, dataType = "int"),
            @ApiImplicitParam(name = "PageSize", value = "页大小", required = true, dataType = "int"),
            @ApiImplicitParam(name = "sex", value = "1男，2女", required = true, dataType = "int"),
            @ApiImplicitParam(name = "real", value = "真人认证，0：不限，1认证", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pretty", value = "女神认证，0：不限，1认证", required = true, dataType = "int")
    })
    @RequestMapping(value = "/broadcastList", method = RequestMethod.GET)
    public Result broadcastList(Integer sex, Integer real, Integer pretty, Integer type, Integer pageNo, Integer pageSize) {
        return Result.success(momentService.broadcastList(sex, real, pretty, type, pageNo, pageSize));
    }

    @ApiOperation(value = "附近的动态(同城)", notes = "查询附近的列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "起始页", required = true, dataType = "int"),
            @ApiImplicitParam(name = "PageSize", value = "页大小", required = true, dataType = "int"),
            @ApiImplicitParam(name = "sex", value = "1男，2女", required = true, dataType = "int"),
            @ApiImplicitParam(name = "real", value = "真人认证，0：不限，1认证", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pretty", value = "女神认证，0：不限，1认证", required = true, dataType = "int"),
            @ApiImplicitParam(name = "longitude", value = "经度", required = true, dataType = "float"),
            @ApiImplicitParam(name = "latitude", value = "纬度", required = true, dataType = "float")
    })
    @RequestMapping(value = "/nearbyList", method = RequestMethod.GET)
    public Result nearbyList(Integer sex, Integer real, Integer pretty, float longitude, float
            latitude, Integer pageNo, Integer pageSize) {
        return Result.success(momentService.nearbyList(sex, real, pretty, longitude, latitude, pageNo, pageSize));
    }


    @RequestMapping(value = "/next", method = RequestMethod.GET)
    public Result next(String momentId) {
        return Result.success(momentService.next(momentId));
    }


    @RequestMapping(value = "/prev", method = RequestMethod.GET)
    public Result prev(String momentId) {
        return Result.success(momentService.prev(momentId));
    }

}

